<template>
  <a-modal v-model="visible" title="任务统计" width="800px" :footer="false">
    <a-form layout="inline" :form="events_form">
      <a-form-item label="员工姓名">
        <a-input placeholder="请输入员工姓名" v-decorator="['name']"></a-input>
      </a-form-item>
      <a-form-item>
        <a-button type='primary' @click="loadTable(true)">查询</a-button>
      </a-form-item>
    </a-form>
    <a-table :columns="table.columns" :data-source="table.loadData" :pagination="table.pagination"
      @change="handleTableChange" rowKey="id">
      <!-- 操作栏-->
      <span slot="action" slot-scope="text, record">
        <!-- 编辑模块 | 字段 -->
        <a @click="goDetail(record)">详情</a>
      </span>
    </a-table>
  </a-modal>
</template>

<script>
import {
  COLUMNS_COMPLIANCETASKCOUNT
} from "./form"
import {
  pageDisabledOverviewData
} from "@/api/human/disabled"
import store from '@/store'
import { mapGetters, mapActions } from 'vuex'
export default {
  name: 'AddInfo',
  data() {
    return {
      title: "",
      visible: false,
      submitLoading: false,
      table: {
        columns: COLUMNS_COMPLIANCETASKCOUNT,
        loadData: [],
        pagination: {
          current: 1,
          pageSize: 10,
          total: 0,
          showSizeChanger: true,
          showQuickJumper: true,
          pageSizeOptions: ["10", "20", "50", "100"],
          showTotal: total => `共有 ${total} 条数据`,
        }
      },

      id: "",
    }
  },
  beforeCreate() {
    this.events_form = this.$form.createForm(this, {
      name: 'events_form'
    });
  },
  computed: {
    ...mapGetters(['userInfo'])
  },
  methods: {
    // 打开编辑弹窗 
    async add(row) {
      this.visible = true;
      this.id = row === true ? '' : row.id;
      this.$nextTick(() => {
        this.events_form.resetFields();
      })
      this.loadTable(true);
    },
    // 获取达标任务列表
    async loadTable(flag) {
      let params = this.events_form.getFieldsValue();
      params.taskBaseId = this.id;
      if (flag) {
        this.table.pagination.current = 1;
        this.table.pagination.pageSize = 10;
      }
      params.pageNum = this.table.pagination.current;
      params.pageSize = this.table.pagination.pageSize;
      const { code, data } = await pageDisabledOverviewData(params);
      if (code == '1') {
        this.table.loadData = data.content || [];
        this.table.pagination.total = data.total || 0;
      }
    },
    handleTableChange(pagination) {
      this.table.pagination.current = pagination.current;
      this.table.pagination.pageSize = pagination.pageSize;
      this.loadTable(false);
    },
    // 详情跳转
    goDetail(row) {
      switch (row.taskType) {
        case 1:
          // 跳转企业宣传
          this.$router.push({ name: 'humanResourcesPublicizeCode', query: { 
            staffId: row.staffId
          }});
          break;
        case 2:
          // 跳转人员信息
          this.$router.push({ name: 'humanResourcesInformationCode', query: { 
            staffId: row.staffId
          }});
          break;
        default:
          // 跳转考勤管理
          this.$router.push({ name: 'humanResourcesAttendanceCode', query: { 
            staffId: row.staffId
          }});
      }
      this.visible = false;
    }
  }
}
</script>
